﻿namespace ScreenShoter
{
	using System;
	using System.Runtime.InteropServices;

	/// <summary>
	/// Contains unmanaged Windows API functions.
	/// </summary>
	internal static class NativeMethods
	{
		/// <summary>
		/// The callback method for a low level keyboard hook.
		/// </summary>
		/// <param name="nCode"></param>
		/// <param name="wParam">Indicates the key state.</param>
		/// <param name="lParam">Indicates which key was pressed.</param>
		/// <returns></returns>
		internal delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);

		[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
		internal static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);

		[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool UnhookWindowsHookEx(IntPtr hhk);

		[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
		internal static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);

		[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
		internal static extern short GetKeyState(int nVirtKey);

		internal static class Constants
		{
			public const int KEY_PRESSED = 0x8000;
			public const int WM_KEYDOWN = 0x0100;
			public const int WM_KEYUP = 0x0101;
			public const int WM_SYSKEYDOWN = 0x0104;
			public const int WM_SYSKEYUP = 0x0105;
			public const int WH_KEYBOARD_LL = 13;
		}
	}
}
